import 'package:flutter/material.dart';

void main() => runApp(HomePage());

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  Offset _offset = Offset.zero;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("3d"),
        ),
        body: Center(
          child: Transform(
            transform: Matrix4.identity()
            ..setEntry(3, 2, 0.002)
              ..rotateX(_offset.dy*0.02)
              ..rotateY(_offset.dx*0.02),
            child: GestureDetector(
              onPanUpdate: (detail) {
                setState(() {
                  _offset += detail.delta;
                });
              },
              onDoubleTap: () {
                // 双击还原动画
              },
              child: Container(
                width: 200,
                height: 200,
                color: Colors.red,
              ),
            ),
          ),
        ),
      ),
    );
  }
}
